﻿using SP.DataExchange.BusMessage;
using SP.DataExchange.ServiceBus;
using System;
using System.Diagnostics;
using NLog;

namespace SP.DataExchange.SubcribTest
{
   public class ServiceHandler
   {
       private IServiceBus _bus;
       private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
        public bool Start()
        {
          _bus=new ServiceBus.ServiceBus();
            try
            {
                _bus.Subscribe<TestLogMessage>("", msg =>
                {
                    Debug.Print(msg.Name);
                    Logger.Info(msg.Name);
                });

                Logger.Info("服务已启动");
                return true;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return false;
            }
        }

        public bool Stop()
        {
            _bus.Dispose();
            return true;
        }
    }
}
